﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Toad.Application.Actions
{
	class InsertDatapathControllerUsingDialogAction : ActionBase
	{
		public InsertDatapathControllerUsingDialogAction()
		{
      Enabled = false;

      Application.Instance.SelectedItemChanged +=
        new EventHandler<SelectedItemChangedEventArgs>(Instance_SelectedItemChanged);
		}

		public override void Execute(object sender, EventArgs e)
		{
			if (Application.Instance.SelectedItem is Items.GezelTextFile)
			{
				Forms.AddDatapathControllerPairForm form =
					new Weazel.Toad.Application.Forms.AddDatapathControllerPairForm();

				System.Windows.Forms.DialogResult result = form.ShowDialog();

				if (result == System.Windows.Forms.DialogResult.OK)
				{
					Items.GezelTextFile file =
						Application.Instance.SelectedItem as Items.GezelTextFile;

					file.TextEditor.TextAreaControl.TextArea.InsertString(form.GezelDescription);
				}
			}
		}

    void Instance_SelectedItemChanged(object sender, SelectedItemChangedEventArgs e)
    {
      if (e.SelectedItem is Items.GezelTextFile)
      {
        Enabled = true;
      }
      else
      {
        Enabled = false;
      }
    }
	}
}
